package com.bi.design.tools;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.io.Serializable;
import java.util.List;

@JsonIgnoreProperties({"orders", "optimizeCountSql", "hitCount", "countId", "maxLimit", "searchCount"})
public class PageInfo<T> extends Page<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private boolean hasNextPage;
    private boolean hasPrevPage;
    private long startIndex;

    public PageInfo(long currentPage, long pageShowCount) {
        super(currentPage, pageShowCount);
        this.startIndex = super.offset();
    }

    public PageInfo() {
        super();
    }


    @Override
    public PageInfo<T> setRecords(List<T> records) {
        super.setRecords(records);
        this.hasNextPage = super.hasNext();
        this.hasPrevPage = super.hasPrevious();
        return this;
    }

    public boolean getHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public boolean getHasPrevPage() {
        return hasPrevPage;
    }

    public void setHasPrevPage(boolean hasPrevPage) {
        this.hasPrevPage = hasPrevPage;
    }

    private boolean hasNextPage(long currentPage, long totalPage) {
        return currentPage < totalPage && totalPage != 0;
    }

    public long getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(long startIndex) {
        this.startIndex = startIndex;
    }
}
